import Vue from 'vue'
import VueRouter from 'vue-router'
import store from "@/store";

Vue.use(VueRouter)

const routes = [{
    path: '/login',
    name: 'login',
    meta: {
      title: '登录'
    },
    component: () => import( /* webpackChunkName: "login" */ '@/views/login')
  }, {
    path: '/',
    name: 'layout',
    meta: {
      title: '首页'
    },
    component: () => import( /* webpackChunkName: "layout" */ '@/views/layout'),
    redirect: () => {
      // 方法接收 目标路由 作为参数
      // return 重定向的 字符串路径/路径对象
      return "/welcome"
    },
    children: [{
      path: 'welcome',
      name: 'welcome',
      meta: {
        title: '欢迎'
      },
      component: () => import( /* webpackChunkName: "layout" */ '@/views/welcome.vue')
    }]
  },
  {
    path: '/pay',
    name: 'pay',
    meta: {
      title: '聚合支付说明'
    },
    component: () => import( /* webpackChunkName: "layout" */ '@/views/layout'),
    children: [{
        path: '/payApi',
        name: 'payApi',
        meta: {
          title: '聚合支付接口'
        },
        component: () => import( /* webpackChunkName: "layout" */ '@/views/pay/payApi')
      },
      {
        path: '/payOrderApi',
        name: 'payOrderApi',
        meta: {
          title: '聚合支付订单接口'
        },
        component: () => import( /* webpackChunkName: "layout" */ '@/views/pay/payOrderApi')
      }
    ]
  },
  {
    path: '/byScanPay',
    name: 'byScanPay',
    meta: {
      title: '聚合主被扫支付说明'
    },
    component: () => import( /* webpackChunkName: "layout" */ '@/views/layout'),
    children: [{
        path: '/byScanPayApi',
        name: 'byScanPayApi',
        meta: {
          title: '用户被扫接口'
        },
        component: () => import( /* webpackChunkName: "layout" */ '@/views/byScanPay/byScanPayApi')
      },
      {
        path: '/byScanMainPayApi',
        name: 'byScanMainPayApi',
        meta: {
          title: '用户主被扫接口'
        },
        component: () => import( /* webpackChunkName: "layout" */ '@/views/byScanPay/byScanMainPayApi')
      },
      {
        path: '/byScanMainOrderPayApi',
        name: 'byScanMainOrderPayApi',
        meta: {
          title: '主被扫订单查询接口'
        },
        component: () => import( /* webpackChunkName: "layout" */ '@/views/byScanPay/byScanMainOrderPayApi')
      },
      {
        path: '/byScanMainRecallPayApi',
        name: 'byScanMainRecallPayApi',
        meta: {
          title: '主被扫订单撤销接口'
        },
        component: () => import( /* webpackChunkName: "layout" */ '@/views/byScanPay/byScanMainRecallPayApi')
      }
    ]
  }, {
    path: '/statistics',
    name: 'statistics',
    meta: {
      title: '统计'
    },
    component: () => import( /* webpackChunkName: "vip" */ '@/views/layout'),
    children: [{
        path: '/index',
        name: 'index',
        meta: {
          title: '汇总统计'
        },
        component: () => import( /* webpackChunkName: "vip" */ '@/views/statistics/index')
      },
      {
        path: '/logs',
        name: 'logs',
        meta: {
          title: '日志'
        },
        component: () => import( /* webpackChunkName: "vip" */ '@/views/statistics/logs')
      }
    ]
  },
]

// console.log(process.env.BASE_URL)

const router = new VueRouter({
  // mode: 'history',
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to, from, next) => {
  // console.log('beforeEach', to, from)
  store.commit('SET_breadcrumb', to);
  store.commit('ADD_menuTabs', to);
  store.commit('SET_menuIndex', to);
  if (to.path == from.path && to.path != '/') return;
  next();
})

export default router